$(function () {
    //变量抽取
    var staffneeds_datagrid = $("#staffneeds_datagrid");
    var staffneedsitem_datagrid = $("#staffneedsitem_datagrid");
    var staffneeds_dialog = $("#staffneeds_dialog");
    var staffneeds_form = $("#staffneeds_form");
    var recruiteditId = null;
    staffneeds_datagrid.datagrid({
        url: '/staffneeds/list',
        toolbar: "#toolbar",
        striped: true,
        rownumbers: true,
        singleSelect: true,
        pagination: true,
        pagePosition: "bottom",
        fitColumns: true,
        fit: true,
        columns: [[
            {
                field: "recruit_plantype",
                title: '计划类别',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    return row.recruit.plantype.name ? row.recruit.plantype.name : '';
                }
            },
            {
                field: "recruit_planName",
                title: '计划名称',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    if (row.recruit.planName != null) {
                        return row.recruit.planName;
                    } else {
                        return '';
                    }
                }
            },
            {
                field: "recruit_inputUser",
                title: '申请人',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    return row.recruit.inputUser.realName ? row.recruit.inputUser.realName : '';
                }
            },
            {
                field: "job", title: '需求岗位', width: 100, align: 'center'
            },
            {
                field: "recruit_doTime",
                title: '计划时间',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    return row.recruit.doTime ? row.recruit.doTime : '';
                }
            }
        ]]
    });


    var methodObj = {
        //刷新
        reload: function reload() {
            staffneeds_datagrid.datagrid("load");
        },

        //取消
        cancel: function cancel() {
            staffneeds_dialog.dialog("close");
        },


        queryItem: function queryItem() {

            var row = staffneeds_datagrid.datagrid('getSelected');
            //recruiteditId赋值
            recruiteditId = row.id;
            if (!row) {
                $.messager.alert('温馨提示', "请选中一条数据", 'warning');
                return;
            }
            staffneeds_dialog.dialog("setTitle", '录入应聘者信息');
            staffneeds_dialog.dialog("open");
        },

        save: function () {

            $('#applicantId').textbox().textbox('setValue', recruiteditId);

            staffneeds_form.form('submit', {
                url: '/applicant/save',
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        staffneeds_dialog.dialog("close");
                        staffneeds_datagrid.datagrid("reload");
                    } else {
                        $.messager.alert('温馨提示', data.msg);
                    }
                }
            });
        }


        /*        audit: function () {
         var row = staffneeds_datagrid.datagrid('getSelected');
         if (!row) {
         $.messager.alert('温馨提示', "请选中一条数据", 'warning');
         return;
         }
         layui.use('layer', function () {
         var layer = layui.layer;
         layer.open({
         content: "确定要引入" + row.dept.name + row.staff.username + "发起的这条招聘计划吗?"
         , btn: ['取消', '拒绝', '确认']
         , yes: function (index, layero) {
         layer.close(index);
         }
         , btn2: function (index, layero) {
         //被拒绝了
         $.ajax({
         url: '/staffneedsNeeds/refuse',
         data: {recruitId: row.id},
         dataType: 'json',
         type: 'post',
         success: function (data) {
         if (data.success) {
         layer.open({
         content: "操作成功",
         btn: ['确认'],
         yes: function (index, layero) {
         layer.close(index);
         }
         });
         } else {
         layer.open({
         content: data.msg,
         btn: ['确认'],
         yes: function (index, layero) {
         layer.close(index);
         }
         });
         }
         }
         });
         },
         btn3: function (index, layero) {
         //同意审核
         $.ajax({
         url: '/staffneedsNeeds/agree',
         data: {recruitId: row.id},
         dataType: 'json',
         type: 'post',
         success: function (data) {
         if (data.success) {
         layer.open({
         content: "请审成功",
         btn: ['确认'],
         yes: function (index, layero) {
         layer.close(index);
         }
         });
         } else {
         layer.open({
         content: data.msg,
         btn: ['确认'],
         yes: function (index, layero) {
         layer.close(index);
         }
         });
         }
         }
         });
         }
         });
         });
         }*/
    };

    //调用方法
    $('a[data-cmd]').click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });

    staffneeds_dialog.dialog({
        width: 450,
        height: 380,
        modal: true,
        closed: true,
        button: "form_btns",
        onClose: function () {
            staffneeds_dialog.form("clear");
        }
    });
});
























